/**
 * 
 */
const roleService = require("../service/role")

module.exports = {
    findAll: async (ctx, next) => {
        let { rolename } = ctx.request.query;
        console.log("rolename", rolename)
        let params = rolename ? { rolename } : {}
        let roleList = await roleService.findAll(params);
        ctx.body = {
            status: 200,
            data: roleList
        }
    },
    create: async function (ctx, next) {
        let { rolename, remark, status = "1" } = ctx.request.body;
        let params = { rolename, remark, status }
        let role = await roleService.create(params)
        ctx.body = {
            status: 200,
            data: role,
            message: "创建成功"
        }
    },
    update: async (ctx, next) => {
        let { rolename, remark, id } = ctx.request.body;
        let params = { rolename, remark, id }
        await roleService.update(params)
        ctx.body = {
            status: 200,
            message: "更新成功"
        }
        // await db.query("update role set rolename = ?,remark = ? where id = ?", [rolename, remark, id]).then(res => {
        //     ctx.body = {
        //         status: 200,
        //         message: "edit role success"
        //     }
        // })
    },
    del: async (ctx, next) => {
        let { id } = ctx.request.body;
        let params = { id }
        await roleService.del(params)
        ctx.body = {
            status: 200,
            message: "删除成功"
        }
        // await db.query("delete from role where id = ?", [id]).then(res => {
        //     ctx.body = {
        //         status: 200,
        //         message: "delete success"
        //     }
        // })
    }
}